//2129.将标题首字母大写
//https://leetcode.cn/problems/capitalize-the-title/?envType=daily-question&envId=2024-03-11
class Solution {
public:
    string capitalizeTitle(string title) {
        int n = title.size();
		int start = 0, pos = 0;
		while (pos < n)
		{
			while (pos < n && title[pos] != ' ') ++pos;
			if (pos - start > 2)
			{
				title[start] = title[start] >= 97 ? title[start] - 32 : title[start];
				for(int i = start+1;i<pos;++i) title[i] = title[i] < 97 ? title[i] + 32 : title[i];
			}
			else for (int i = start; i < pos; ++i) title[i] = title[i] < 97 ? title[i] + 32 : title[i];
			start = pos + 1;
			++pos;
		}
		
        return title;
    }
};